package JavaFoundation.arrayFoundation;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;

/*
集合的不安全问题
 */
public class ArrayListDome {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        new CopyOnWriteArrayList<String>();
        //List<String> list = Arrays.asList("a","b","c","d");
        //list.forEach(System.out::println);
        //在线程并发的情况下add方法是线程不安全的
        for (int i = 1; i <= 30; i++) {
            new Thread(()->{
               list.add(UUID.randomUUID().toString().substring(0,8));
                System.out.println(list);
            },String.valueOf(i)).start();
        }
        //会报一个java.util.ConcurrentModificationException

    }
}
